<?php
/** $Id: default_form.php 11917 2009-05-29 19:37:05Z ian $ */
defined( '_JEXEC' ) or die( 'Restricted access' );

	$script = '<!--
		function validateForm( frm ) {
			var valid = document.formvalidator.isValid(frm);
			if (valid == false) {
				// do field validation
				if (frm.email.invalid) {
					alert( "' . JText::_( 'Please enter a valid e-mail address.', true ) . '" );
				} else if (frm.text.invalid) {
					alert( "' . JText::_( 'CONTACT_FORM_NC', true ) . '" );
				}
				return false;
			} else {
				frm.submit();
			}
		}
		// -->';
	$document =& JFactory::getDocument();
	$document->addScriptDeclaration($script);
//    $template_dir = $this->baseurl.'/templates/mwc_careitec/assets/';
	$template_dir = '/templates/mwc_careitec/assets/';
	
	if(!empty($this->error)){
        echo '<div>' . $this->error . '</div><br />';
    }
?>
 
<style>
    .required-field{color:#FF0000}
</style>

<form action="<?php echo JRoute::_('index.php') ?>" method="post" name="selectForm" id="selectForm">
    <label for="contact_contact" class="lbl_con"><?php echo JText::_( 'CONTACT_NAME' );?>:</label>
    <input type="text" class="txt_con" id="contact_contact" name="contact_contact" />
    <br/>
    <label for="contact_email" class="lbl_con"><?php echo JText::_( 'Email' );?>&nbsp;<span class="required-field">*</span>:</label>     
    <input type="text" class="txt_con" id="contact_email" name="email" value="" />
    <br/>      
    <label for="contact_name" class="lbl_con"><?php echo JText::_( 'Name' );?>&nbsp;<span class="required-field">*</span>:</label>
    <input type="text" class="txt_con" id="contact_name" name="name" value="" />
    <br/>
    <label for="contact_subject" class="lbl_con"><?php echo JText::_( 'Subject' );?>&nbsp;<span class="required-field">*</span>:</label>
    <input type="text" class="txt_con" id="contact_subject" name="subject" value="" /> 
    <br/>
    <label for="contact_text" class="lbl_con"><?php echo JText::_( 'Message' );?>&nbsp;<span class="required-field">*</span>:</label>      
    <textarea class="txt_con1" id="contact_text" name="text"></textarea>
    <br/>
    <label for="contact_accept" class="lbl_con">&nbsp;</label> 
    <input type="checkbox" class="float_left" id="contact_newsletter" name="newsletter" />
    <div class="float_left m2b" style="width:230px;">&nbsp;<?php echo JText::_('NEWSLETTER'); ?></div> 
    <div class="cb"></div>
    <label class="lbl_con">&nbsp;</label>
    <a id="contact_send" href="#"><img src="<?php echo $template_dir; ?>images/send_but.jpg" alt="" /></a> 
    <a id="contact_reset" href="#"><img src="<?php echo $template_dir; ?>images/nul_but.jpg" alt="" /></a>    
    
    <input type="hidden" name="option" value="com_contact" />
    <input type="hidden" name="view" value="contact" />
    <input type="hidden" name="id" value="<?php echo $this->contact->id; ?>" />
    <input type="hidden" name="task" value="submit" />
    <input type="hidden" name="category_id" value="<?php echo JRequest::getVar('category_id', 0, 'get'); ?>" />
    <input type="hidden" name="Itemid" value="<?php echo JRequest::getVar('Itemid', 0, 'get'); ?>" />
     
    <?php echo JHTML::_( 'form.token' ); ?>
</form>
<div class="cb"></div> 

<script type="text/javascript"><!--
    jQuery(document).ready(function(){ 
        jQuery('#contact_send').click(function(e){
            e.preventDefault();
            jQuery('#selectForm').submit();              
        });
        
        jQuery('#contact_reset').click(function(e){
            e.preventDefault();
            document.selectForm.reset();            
        });
        
        jQuery('#selectForm').submit(function(){
            var email   = jQuery('#contact_email').val();
            var name    = jQuery('#contact_name').val();
            var subject = jQuery('#contact_subject').val();            
            var message = jQuery('#contact_text').val();             
            
            if(email == '' || !isValidEmail(email)){    
                show_popup('<?php echo JText::_( 'EMAIL_ERROR' ); ?>', 'contact_email');
                return false;    
            }
            if(name == ""){
                show_popup('<?php echo JText::_( 'FULLNAME_ERROR' ); ?>', 'contact_name');
                return false;    
            }
            if(subject == ""){
                show_popup('<?php echo JText::_( 'SUBJECT_ERROR' ); ?>', 'contact_subject');
                return false;    
            }             
            if(message == ""){
                show_popup('<?php echo JText::_( 'MESSAGE_ERROR' ); ?>', 'contact_text');
                return false;    
            }                
        });
    });
    
    function isValidEmail(email){
        var filter = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        return filter.test(email);
    }   
    
//-->
</script>
